package com.fishing.controller;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fishing.entity.Loginquery;
import com.fishing.service.LoginqueryService;

/**
 * @author Lrz
 * 登录加载
 * */

@Controller
public class LoginqueryController {
	@Autowired
	private LoginqueryService loginqueryservice;
	

	@RequestMapping(value="loginquery/toList")
	public ModelAndView toList(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("safequery/loginquerytoList");
		return mav;
	}
	
	@ResponseBody
	@RequestMapping(value="loginquery/list",method = RequestMethod.POST,produces="text/html;charset=utf-8")
	public Map<String,Object> list(HttpServletRequest request){
		try {
			List<Loginquery> loginquery = this.loginqueryservice.selectAll();
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("status", "200");
			map.put("message", "");
			map.put("count", loginquery.size());
			map.put("data", loginquery);
			return map;
		} catch (Exception e) {
			e.printStackTrace();
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("status", "200");
			map.put("message", "");
			map.put("count", 0);
			map.put("data", 0);
			return map;
		}
	}
	
	@ResponseBody
	@RequestMapping(value="loginquery/remove",method = RequestMethod.POST,produces="text/html;charset=utf-8")
    public String remove(HttpServletRequest request,int id,String IP) {
		try {
			this.loginqueryservice.deleteByPrimaryKey(id);
			Enumeration em = request.getSession().getAttributeNames();
			while(em.hasMoreElements()) {
				request.getSession().removeAttribute(em.nextElement().toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "fail";
		}
		return "success";
	}

}
